load("@rules_cc//cc:defs.bzl", "cc_library")

cc_library(
    name = "reproc",
    srcs = [
        "reproc/src/clock.h",
        "reproc/src/drain.c",
        "reproc/src/error.h",
        "reproc/src/handle.h",
        "reproc/src/init.h",
        "reproc/src/macro.h",
        "reproc/src/options.c",
        "reproc/src/options.h",
        "reproc/src/pipe.h",
        "reproc/src/process.h",
        "reproc/src/redirect.c",
        "reproc/src/redirect.h",
        "reproc/src/reproc.c",
        "reproc/src/run.c",
        "reproc/src/strv.c",
        "reproc/src/strv.h",
        "reproc/src/utf.h",
        "reproc/src/utf.posix.c",
    ] + select({
        "@platforms//os:windows": [
            "reproc/src/clock.windows.c",
            "reproc/src/error.windows.c",
            "reproc/src/handle.windows.c",
            "reproc/src/init.windows.c",
            "reproc/src/pipe.windows.c",
            "reproc/src/process.windows.c",
            "reproc/src/redirect.windows.c",
            "reproc/src/utf.windows.c",
        ],
        "//conditions:default": [
            "reproc/src/clock.posix.c",
            "reproc/src/error.posix.c",
            "reproc/src/handle.posix.c",
            "reproc/src/init.posix.c",
            "reproc/src/pipe.posix.c",
            "reproc/src/process.posix.c",
            "reproc/src/redirect.posix.c",
        ],
    }),
    defines = select({
        "@platforms//os:windows": ["WIN32_LEAN_AND_MEAN=1"],
        "//conditions:default": [],
    }),
    hdrs = [
        "reproc/include/reproc/drain.h",
        "reproc/include/reproc/export.h",
        "reproc/include/reproc/reproc.h",
        "reproc/include/reproc/run.h",
        "reproc/src/process.posix.c",
    ],
    includes = ["reproc/include"],
    linkopts = select({
        "@platforms//os:windows": [
           "-DEFAULTLIB:ws2_32",
           "-DEFAULTLIB:mswsock",
        ],
        "//conditions:default": [],
    }),
    visibility = ["//visibility:public"],
)

cc_library(
    name = "reproc++",
    srcs = ["reproc++/src/reproc.cpp"],
    hdrs = [
        "reproc++/include/reproc++/arguments.hpp",
        "reproc++/include/reproc++/detail/array.hpp",
        "reproc++/include/reproc++/detail/type_traits.hpp",
        "reproc++/include/reproc++/drain.hpp",
        "reproc++/include/reproc++/env.hpp",
        "reproc++/include/reproc++/export.hpp",
        "reproc++/include/reproc++/input.hpp",
        "reproc++/include/reproc++/reproc.hpp",
        "reproc++/include/reproc++/run.hpp",
    ],
    includes = ["reproc++/include"],
    visibility = ["//visibility:public"],
    deps = [":reproc"],
)
